package com.hiraeth.modules.monitor.controller;

import com.hiraeth.common.utils.R;
import com.hiraeth.modules.monitor.model.ScrapeConfig;
import com.hiraeth.modules.monitor.service.JobService;
import com.hiraeth.modules.monitor.service.MonitorAlertNotificationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/monitor/job")
public class JobController {

    @Autowired
    private JobService jobService;

    @Autowired
    private MonitorAlertNotificationService monitorAlertNotificationService;

    /**
     * 查询prometheus job列表
     * @return
     */
    @GetMapping("/list")
    @RequiresPermissions("monitor:job:list")
    public List<ScrapeConfig> list(){
        return jobService.getJobList();
    }

    /**
     * 新增prometheus job信息
     * @param scrapeConfig
     * @return
     */
    @PostMapping("/static/save")
    @RequiresPermissions("monitor:job:static:save")
    public R saveStatiConfigJob(@RequestBody ScrapeConfig scrapeConfig) {
        return jobService.saveStatiConfigJob(scrapeConfig);
    }

    /**
     * 更新prometheus job信息
     * @param scrapeConfig
     * @return
     */
    @PostMapping("/static/update")
    @RequiresPermissions("monitor:job:static:update")
    public R updateStatiConfigJob(@RequestBody ScrapeConfig scrapeConfig) {
        return jobService.updateStatiConfigJob(scrapeConfig);
    }

    /**
     * 删除prometheus job信息
     * @param job_name
     * @return
     */
    @PostMapping("/static/delete")
    @RequiresPermissions("monitor:job:static:delete")
    public R deleteStatiConfigJob(@RequestBody String job_name) {
        return jobService.deleteStatiConfigJob(job_name);
    }
}
